import React from 'react';
import {  Text,View,Button } from 'react-native';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import * as homeActions from '../actions/home';

class HomeScreen extends React.Component {
  static navigationOptions = {
    title: 'Welcome',
  };

  onButtonPress = ()=>{
      this.props.actions.demoAction(this.props.demo);
  }
  render() {
    return (
        <View>
            <Button
            onPress={this.onButtonPress} 
            title="点我通过redux改变值"
            />
            <Text>点击+1：{this.props.demo}</Text>
        </View>
    )
  }
}

const mapStateToProps = (state) => ({
    demo: state.data.demo,
});

const mapDispatchToProps = (dispatch) => {
  return {
    actions:bindActionCreators(homeActions, dispatch)
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
